/******************************************************
* Team WB
* Brett Cate, William Kim
* 
* Sandbox testing file
*******************************************************/

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "sc2.h"
#include "register16.h"

int notmain() {
	ushort testshort = 0xFFFF;
	testshort = testshort | 0xFFFF0000;
	
	printf("%d",testshort);

	//srand((unsigned) time(NULL)); // Sets the seed for random number generation using the current time


	
//	printf("%d %d %d", testshort, testshort + 20, 270);
//	test_register_signOf();
//	test_register_putLowByte();
//	test_register_putHIByte();
//	test_register_getLowByte();
//	test_register_getHIByte();
//	testUshortToUchar();
//	test_register_new();
	getchar();
}

int test_register_signOf() {
	RegisterPtr r = register_new();
	uchar signOf;
	int error;
	register_putRegValue(r, 0xF000);
	signOf = register_signOf(r, &error);
	printf("Register contents before signOf() Call: %x\n", *r);
	printf("signOf() return value: %d   Error Code: %d", signOf, error);
}

int test_register_putLowByte() {
	RegisterPtr r = register_new();
	uchar my_char;
	int error;
	register_putRegValue(r, 0xDEED);
	my_char = 0x22;
	printf("Register contents before putLowByte() Call: %x\n", *r);
	error = register_putLowByte(r, my_char);
	printf("Register contents after putLowByte() Call: %x   Error code: %d\n", *r, error);
}

int test_register_putHIByte() {
	RegisterPtr r = register_new();
	uchar my_char;
	int error;
	register_putRegValue(r, 0xDEAD);
	my_char = 0xBB;
	printf("Register contents before putHIByte() Call %x\n", *r);
	error = register_putHIByte(r, my_char);
	printf("Register contents after putHIByte() Call: %x   Error code: %d\n", *r, error);
}

int test_register_getLowByte() {
	RegisterPtr r = register_new();
	uchar my_char;
	int the_error;
	register_putRegValue(r, 0xFEED);
	my_char = register_getLowByte(r, &the_error);
	printf("Low Order byte contains : %x   Error Code %d\n", my_char, the_error);
	my_char = register_getLowByte(NULL, &the_error);
	printf("Null test my_char: %x   Null test Error Code: %d\n", my_char, the_error);
}

int test_register_getHIByte() {
	RegisterPtr r = register_new();
	uchar my_char;
	int the_error;
	register_putRegValue(r, 0xFEED);
	my_char = register_getHIByte(r, &the_error);
	printf("High Order byte contains : %x   Error Code: %d\n", my_char, the_error);
	my_char = register_getHIByte(NULL, &the_error);
	printf("Null test my_char: %x   Null test Error Code: %d\n", my_char, the_error);
}

int testUshortToUchar() {
	RegisterPtr r = register_new();
	RegisterPtr r2 = register_new();
	uchar my_char;
	register_putRegValue(r, 0x1234);
	printf("register r: %x \n", *r);
	my_char = (uchar) *r; // This cast results in my_char receiving the low order byte of the ushort 'r';
//	my_char = *r >> 8; This statement results in my_char receiveing the high order byte of the ushort 'r';
	// The operator >> is a bitwise shift to the right.
	printf("uchar with contents of register r: %x \n", my_char);
	return NO_ERROR;
}

int test_register_new() {
	RegisterPtr new_reg = register_new();
	printf("new_reg contents at initialization : %x \n", *new_reg);
	return NO_ERROR;
}